<?php
/**
 *  模型类
 */
namespace app\admin\model;
use think\Model;

class Message extends Model
{

    // 获取列表
    public function getList($UrlParam,$PageCount)
    {
        return $this->where("acode='" . session('acode') . "'")
            ->order('id DESC')
            ->paginate($PageCount,false,['query' => $UrlParam]);
    }

    // 获取详情
    public function getMessage($id)
    {
        return $this->where("id=$id")
            ->where("acode='" . session('acode') . "'")
            ->find();
    }

    // 删除留言
    public function delMessage($id)
    {
        return $this->where("id=$id")
            ->where("acode='" . session('acode') . "'")
            ->delete();
    }

    // 修改留言
    public function modMessage($id, $data)
    {
        return $this->autoTime()
            ->where("id=$id")
            ->where("acode='" . session('acode') . "'")
            ->update($data);
    }

    // 获取表单字段
    public function getFormFieldByCode($fcode)
    {
        return $this->table('ay_form_field')->where("fcode='$fcode'")
            ->order('sorting ASC,id ASC')
            ->select();
    }

    // 获取留言数量
    public function getCount()
    {
        $rs = $this->field('count(*) as count')
            ->where("acode='" . session('acode') . "'")
            ->find();
        return $rs->count ?: 0;
    }
}